#include "Modifier/GameModifier.h"
#include "Modifier/CatObstacleInstruction.h"
#include "Director/DirectorLoader.h"
#include "CatObstacle.h"

//===== PUBLIC FUNCTIONS =====
CatObstacle::~CatObstacle(void)
{

}

/*!
    @function update
    @param		difficulty: int
				new difficulty level to determine factor contribution
    @result		update the current difficulty level
    			sends a Modifier Instruction if new difficulty is set
*/
void CatObstacle::update(int difficulty)
{
	if( updateDifficulty(difficulty) )
	{
		// Send Instructions for new difficulty
		GameModifier::getInstance().modify( new CatObstacleInstruction( getObstacleChance() ));
	}

	// Else, no change
}

//===== PRIVATE FUNCTIONS =====

/*!
    @function setEquationVariable
    @result		set variable K and C to be used in the equation, y = ke^-x + c
 */
void CatObstacle::setEquationVariable()
{
	// Difficulty level is an negative-exponential curve
	// y-axis 1 ~ 100, x-axis 0.5~1.0
	float POINT_Y1 = _weight * DirectorLoader::CAT_OBSTACLE_Y1;	// y-pos in eqn
	float POINT_Y2 = _weight * DirectorLoader::CAT_OBSTACLE_Y2;

	float POINT_X1 = DirectorLoader::CAT_OBSTACLE_X1;	// x-pos in eqn, chance/100
	float POINT_X2 = DirectorLoader::CAT_OBSTACLE_X2;

	_varK = DirectorLoader::getNegLogVarK(POINT_Y1, POINT_Y2, POINT_X1, POINT_X2);
	_varC = DirectorLoader::getNegLogVarC(_varK, POINT_Y1, POINT_X1);
}

/*!
    @function getCharacterSpeed
    @result		find character speed based on y = ke^-x + c
    			x = - log ( (y-c)/k ) * 100.0 (obstacle chance)
*/
float CatObstacle::getObstacleChance()
{
	float result = DirectorLoader::getNegLogValue(_varK, _varC, _currentDifficulty);
	if( result < DirectorLoader::CAT_OBSTACLE_X1 ) result = DirectorLoader::CAT_OBSTACLE_X1;
	return ( result * 100.0 );
}

